package cn.sytton.taffe.framework.base.entity;

import cn.sytton.taffe.framework.util.SecurityUtil;
import com.baomidou.mybatisplus.annotation.FieldStrategy;
import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.sql.Timestamp;
import java.util.Date;

/**
 * 业务实体类,包括基础的4个基础字段
 *
 * @author skyrock
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class BaseUpdatedEntity extends BaseCreatedEntity {
    /**
     * 最近一次更新userId
     */
    @JsonIgnore
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private String updatedUserId;
    /**
     * 最近一次更新时间
     */
    @JsonIgnore
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private Timestamp updatedTime;

    public Timestamp newTimestamp() {
        return new Timestamp(new Date().getTime());
    }

    public void updateField() {
        this.updatedTime = newTimestamp();
        this.updatedUserId = SecurityUtil.getUserId();
    }
}
